package cn.java81.single;

/**
 * @author oldliu
 * @since 1.0
 */
public class Sun2 {
    //饿汉
    private static Sun2 inst;
    private Sun2(){
        System.out.println("太阳2被构建出来了。。。");
    }
    //有线程同步问题
//    public static Sun2 getInstance(){
////        if(inst==null){
////
////                    inst=new Sun2();
////
////        }
////        return inst;
////    }
    //DCL
    public static Sun2 getInstance(){
        if(inst==null){
            synchronized (Sun2.class){
                if(inst==null){
                    inst=new Sun2();
                }
            }
        }
        return inst;
    }
    public void shine(){
        System.out.println("太阳发着光芒万丈");
    }
}
